import React from 'react';
import {
  View,
  Image,
  Text,
  StyleSheet,
  TouchableOpacity,
  Platform
} from 'react-native';

import CommonListPage from '../common/CommonListPage';
import SizeUtils from '../../common/SizeUtils';
import PostConstants from '../../common/PostConstants';
import Config from '../../config';
import CommonDataListView from '../common/CommonDataListView';
import PostRequestListAction from '../../actions/post/PostRequestListAction';
import BaseItem from '../common/BaseItem';
import CommonStyles from '../../common/CommonStyles';
import {DateUtils} from '../../utils/Utils';
import TImage from '../../components/TImage';

export default class VipHaveQuestPage extends CommonListPage {
  constructor(props) {
    super(props);

    this._viewPager = null;
    this._dataKey = "post_id";
  }

  _getListViewStyle() {
    return {
        alignItems: 'center',
        width:SizeUtils.getWindowSize().width - SizeUtils.translateDesignWidthToCode(25),
        height:(SizeUtils.getWindowSize().height - Config.paddingTop),
        backgroundColor:"#ffffff"};
  }

  _getViewStyle() {
    return {paddingTop:Platform.OS === "ios"?(Config.paddingTop + SizeUtils.translateDesignHeightToCode(20)):SizeUtils.translateDesignHeightToCode(66),justifyContent: 'space-around',
        paddingLeft:SizeUtils.translateDesignHeightToCode(20), backgroundColor:"#ffffff"}
  }

  _requestData(page, listView) {
      new PostRequestListAction().call(listView, {board_id:PostConstants.BOARD_ID.VIP_REQUESTION, page:page, page_size:10, sort_id:1});
      if(this._listView != null){
         this._listView.doRefresh();
      }
  }

  _onRenderItem(data, rowID) {
    if(data != null)
    {
      return (
        <Item key={rowID} data={data} rowID={rowID} />
      )
    }
  }

  _onPressItem(data, index) {
    if(data != null)
    {
      this.gotoPage(Config.pages.vipquestcontent, data);
    }
  }
}

class Item extends BaseItem {
  constructor(props) {
    super(props);
  }

  shouldComponentUpdate(nextProps, nextState) {
    return this.props.data != nextProps.data;
  }

  render() {
    return (
        <View
          style={{flex:1, flexDirection:"row",
              alignItems: 'center',
              paddingLeft:SizeUtils.translateDesignWidthToCode(40),backgroundColor:"#ffffff",
              width:SizeUtils.translateDesignWidthToCode(715),
              paddingRight:SizeUtils.translateDesignWidthToCode(40), borderColor:"#eeeeee",
              paddingBottom:SizeUtils.translateDesignHeightToCode(20),
              paddingTop:SizeUtils.translateDesignHeightToCode(20),
              borderBottomWidth:SizeUtils.translateDesignNumToCode(3)}}>
            <View style={{flex:1, flexDirection: "column", paddingTop:SizeUtils.translateDesignHeightToCode(0)}}>
                <View>
                  <Text numberOfLines={1}
                    style={[CommonStyles.primaryText, {fontSize:SizeUtils.translateFontSizeToCode(26)}]}>
                      {this.props.data.title}
                  </Text>
                </View>
            </View>
        </View>

    )
  }
}
